# -*- coding: utf-8 -*-

################################################################################
## Form generated from reading UI file '实现将系统图片显示在标签上.ui'
##
## Created by: Qt User Interface Compiler version 5.15.2
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################

from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWidgets import *
from PySide2 import QtWidgets, QtGui, QtCore
import sys


class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        if not MainWindow.objectName():
            MainWindow.setObjectName(u"MainWindow")
        MainWindow.resize(800, 600)
        self.centralwidget = QWidget(MainWindow)
        self.centralwidget.setObjectName(u"centralwidget")
        self.pushButton = QPushButton(self.centralwidget)
        self.pushButton.setObjectName(u"pushButton")
        self.pushButton.setGeometry(QRect(150, 90, 93, 28))

        # 为按钮设置信号与槽函数
        self.pushButton.clicked.connect(self.openimage)

        self.label = QLabel(self.centralwidget)
        self.label.setObjectName(u"label")
        self.label.setGeometry(QRect(150, 150, 431, 291))

        # 设定label的初始的显示格式
        self.label.setStyleSheet("QLabel{background:white;}"
                                 "QLabel{color:rgb(300,300,300,120);font-size:72px;font-weight:bold;font-family:宋体;}"
                                 )
        self.label.setAlignment(Qt.AlignCenter)   # 设置label的文字显示，显示在中间

        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QMenuBar(MainWindow)
        self.menubar.setObjectName(u"menubar")
        self.menubar.setGeometry(QRect(0, 0, 800, 26))
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QStatusBar(MainWindow)
        self.statusbar.setObjectName(u"statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)

        QMetaObject.connectSlotsByName(MainWindow)
    # setupUi

    def retranslateUi(self, MainWindow):
        MainWindow.setWindowTitle(QCoreApplication.translate("MainWindow", u"\u5b9e\u73b0\u6253\u5f00\u7cfb\u7edf\u6587\u4ef6\u4e2d\u56fe\u7247\uff08\u663e\u793a\u5728\u6807\u7b7e\u4e0a\uff09", None))
        self.pushButton.setText(QCoreApplication.translate("MainWindow", u"\u6253\u5f00\u6587\u4ef6", None))
        self.label.setText(QCoreApplication.translate("MainWindow", u"\u56fe\u7247\u663e\u793a", None))
    # retranslateUi

    # 定义槽函数
    def openimage(self):
        imgName, imgType = QFileDialog.getOpenFileName(None, "打开图片", "", "*.jpg;;*.png;;All Files(*)")
        jpg = QtGui.QPixmap(imgName).scaled(self.label.width(), self.label.height())
        # 解释scaled(self.label.width(), self.label.height()) 方法是要自动调节图片显示大小
        self.label.setPixmap(jpg)


if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())


# 思路整理：
#   1.通过QFileDialog.getOpenFileName（）获取系统图片文件的地址（和类型）
#   2.通过QtGui.QPixmap创建一个图片对象（其中图片位置参数，就是上面获取到的地址参数）
#   3.通过label.setPixmap（创建的图片对象）来实现在label上显示图片


